<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
        v-model="keyWord"
      />&nbsp;
      <button @click="findUser">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Seatch",
  data() {
    return {
      keyWord: "",
    };
  },
  methods: {
    findUser() {
      this.$bus.$emit("getUsers", {
        userList: [],
        isFrist: false,
        err: "",
        isLoading: true,
      }),
        axios
          .get(`https://api.github.com/search/users?q=${this.keyWord}`)
          .then((res) => {
            console.log("cg", res.data);
            this.$bus.$emit("getUsers", {
              userList: res.data.items,
              isFrist: false,
              err: "",
              isLoading: false,
            });
          })
          .catch((err) => {
            console.error(err.message);
            this.$bus.$emit("getUsers", {
              userList: [],
              isFrist: false,
              err: err.message,
              isLoading: false,
            });
          });
    },
  },
};
</script>

<style>
</style>